package class_load;

import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Properties;

/**
 * @program: baseModule
 * @description:
 * @author: zhanghz001
 * @create: 2020-10-28 10:32
 **/
public class ClassDemo {
    @Test
    public void testClassLoader2() throws IOException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        Constructor<Student> constructor =
                Student.class.getDeclaredConstructor(
                        String.class, int.class);
        constructor.newInstance("zhangsan", 21);
    }

    @Test
    public void testClassLoader1() throws IOException {
        //classLoader 方法两个
        ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();

        //加载资源文件
        InputStream is = systemClassLoader.getResourceAsStream("user.properties");
        // systemClassLoader.getResourceAsStream()
        Properties pro = new Properties();
        pro.load(is);
        System.out.println(pro.getProperty("username"));
        is.close();
    }

    @Test
    public void testClassLoader() {
        ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
        ClassLoader parent = systemClassLoader.getParent();
        ClassLoader parent1 = parent.getParent();
        System.out.println(systemClassLoader);
        System.out.println(parent);
        // ClassLoader platformClassLoader = ClassLoader.getPlatformClassLoader();
        // System.out.println(platformClassLoader);
        // System.out.println(parent1);
    }

    @Test
    public void testClassName() {
        Student name = new Student(10, "name");
        System.out.println(name);
        Class<Student> aClass = Student.class;
        System.out.println(ClassDemo.class.getName());

    }
}
